package cn.school.controller.studyManage;

import cn.school.common.api.CommonPage;
import cn.school.common.api.CommonResult;
import cn.school.common.exception.ApiException;
import cn.school.studyManage.dto.StudentBehaviorCfgDTO;
import cn.school.studyManage.entity.StudentBehaviorCfg;
import cn.school.studyManage.service.StudentBehaviorCfgService;
import cn.school.studyManage.vo.StudentBehaviorCfgQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 学生行为配置控制器
 */

@RestController
@Api(tags = {"StudentBehaviorCfgController => 学生行为配置控制器"})
@RequestMapping("student/behavior/cfg")
public class StudentBehaviorCfgController {

    @Autowired
    StudentBehaviorCfgService cfgService;

    @ApiOperation("list => 分页查询行为配置")
    @PostMapping("/findCfgPageList")
    public CommonResult<CommonPage<StudentBehaviorCfg>> findCfgPageList(@RequestBody StudentBehaviorCfgQueryVo vo)throws ApiException{
        IPage<StudentBehaviorCfg> pageList = cfgService.findCfgPageList(vo);
        return CommonResult.success(CommonPage.restPage(pageList));
    }

    @ApiOperation("createOrUpdate => 新增或更新配置")
    @PostMapping("/createOrUpdateCfg")
    public CommonResult createOrUpdateCfg(@RequestBody StudentBehaviorCfgDTO dto)throws ApiException {
        boolean flag = cfgService.createOrUpdateCfg(dto);
        if(flag){
            return CommonResult.success();
        }
        return CommonResult.failed("failed");
    }

    @ApiOperation("delete => 删除配置")
    @DeleteMapping("/delCfg/{id}")
    public CommonResult delCfg(@PathVariable("id")Long id)throws ApiException{
        boolean flag = cfgService.delCfg(id);
        if(flag){
            return CommonResult.success();
        }
        return CommonResult.failed("failed");
    }

    @ApiOperation("find => 根据教师查询配置")
    @GetMapping("/findCfgByTeacher")
    public CommonResult findCfgByTeacher() throws ApiException{
        cfgService.findCfgByTeacher();
        return CommonResult.success();
    }
}
